function get_all_pathways2()
    tStartMain = tic;
    disp('Start pathways search .. ');
    assignin('base', 'listOfPathways', []); 

    modelIsUsed = checkConnectionMetabolitesOrModelIsUsed();

    if strcmp(modelIsUsed, 'connectionMetabolites')
        metabolites = evalin('base','connectionMetabolites');
    elseif strcmp(modelIsUsed, 'model')
        model = evalin('base', 'model');
        metabolites = unique(model.metKEGGID);
        metabolites = metabolites(~cellfun('isempty',metabolites));  
        clear model;
    else
        msgbox('Execution is cancelled. You can currate the model and continue search of pathways manually.','Execution is cancelled')
        return;
    end

    graphEdges = evalin('base', 'graphEdges');
    graphNodes = evalin('base', 'graphNodes');
    graphNodesNames = graphNodes(:,1);
    
    edgesLength = length(graphEdges);
    nodesLength = length(graphNodesNames);
    totalNodesCount = nodesLength * edgesLength;
    activeNodeNumber = 0;
    
    clear graphNodes;
    clear graphEdges;
    sMatrix = evalin('base', 'sMatrix');
    defines = evalin('base','defines');
    sourceNamed = defines.initialCompound;
    sourceIndex = 1;
    
    listOfReactionsIndexes = [];
    for iSetReactIndexes = 1:length(graphNodesNames)
       if ~isempty(regexp(graphNodesNames{iSetReactIndexes},'R'))
            listOfReactionsIndexes = [listOfReactionsIndexes,iSetReactIndexes];
       end
    end

     foundPathways={};
     pathwaysToReturn ={};

     h = waitbar(0,'Please wait... Looking for pathways');
      
     foundPathways = find_pathways_in_graph(sourceIndex, null(1), ...
                null(1), foundPathways, sourceIndex);
     close(h)
     
     for jPathTOReturn = 1:length(foundPathways)
           foundPathwayKEGGIDs = [];
           for kPathTOReturn = 1:length(foundPathways{jPathTOReturn})
                 foundPathwayKEGGIDs = [foundPathwayKEGGIDs;  graphNodesNames{foundPathways{jPathTOReturn}(kPathTOReturn)}];
           end 
           pathwaysToReturn = [pathwaysToReturn; foundPathwayKEGGIDs];
     end
            

    function listOfFoundPathways = find_pathways_in_graph(sourceOfGraph, currentPath, ...
         exploreredNodes, listOfFoundPathways, previousSource)
        
         activeNodeNumber = activeNodeNumber + 1;
         
         waitbar(activeNodeNumber/totalNodesCount, h, [num2str(activeNodeNumber), ' nodes of ', ... 
            num2str(totalNodesCount), ' total', ' (', num2str(nodesLength), 'x', num2str(edgesLength), ')' ])
         drawnow update
        
         exploreredNodes = [exploreredNodes, sourceOfGraph];
         currentPath = [currentPath, sourceOfGraph];
        
         if regexp(graphNodesNames{sourceOfGraph}, 'C') == 1
            for jMainLoop = 1:length(metabolites)
                if strcmp(graphNodesNames{sourceOfGraph}, metabolites{jMainLoop})
                    listOfFoundPathways{1, length(listOfFoundPathways) + 1} = currentPath;
                end
            end
         end
        
        if length(currentPath) < (str2num(defines.lengthOfBuildPathways) * 2 + 1)
           neighbours = local_graph_traverse(sMatrix, sourceOfGraph, 'Depth', 1);
           for vFindPath = 2:length(neighbours)
               if ~ismember(neighbours(vFindPath),exploreredNodes)
                   isOnTheSameSideOfEquation = false;
                   isCorrectDirection = true;
                   if ismember(sourceOfGraph, listOfReactionsIndexes)
                       RKEGGID = graphNodesNames{sourceOfGraph};
                       aMetabolite = graphNodesNames{neighbours(vFindPath)};
                       bMetabolite = graphNodesNames{previousSource};
                       equation = get_equation_of_reaction(RKEGGID);
                       isOnTheSameSideOfEquation = ...
                          are_metabolites_on_one_side_of_equation( ...
                          aMetabolite, bMetabolite, equation);
                      if strcmp(defines.isThermodinamicUsed, 'true')
                        isCorrectDirection = get_reaction_dirrection_by_thermodinamics(RKEGGID, equation, aMetabolite);
                      end
                   end                  
                   if ~isOnTheSameSideOfEquation & isCorrectDirection
                        if ~ismember(sourceOfGraph, listOfReactionsIndexes)
                           listOfFoundPathways = find_pathways_in_graph(neighbours(vFindPath),...
                           currentPath,exploreredNodes,listOfFoundPathways, sourceOfGraph);
                        else
                            listOfFoundPathways = find_pathways_in_graph(neighbours(vFindPath),...
                            currentPath,exploreredNodes,listOfFoundPathways,previousSource);
                        end
                   end
                end
            end
        end
    end

    function varargout = local_graph_traverse(varargin)
        [varargout{1:nargout}] = graphtraverse(varargin{1},varargin{2:end});
    end

 tElapsedMain = toc(tStartMain)
 assignin('base', 'listOfPathways', pathwaysToReturn); 
 assignin('base', 'tElapsed_PathwaysSearch', tElapsedMain);
 clear defines;
 clear sMatrix;
 clear pathwaysToReturn;
end
